// 发表评论
function addComment() {
    const content = document.getElementById('commentContent').value.trim();
    if (!content) {
        alert('请输入评论内容');
        return;
    }

    const coupleId = window.location.pathname.split('/')[2];

    fetch(`/couples/${coupleId}/comment`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        body: `content=${encodeURIComponent(content)}`
    })
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                alert('评论成功');
                location.reload();
            } else {
                alert(data.message || '评论失败');
            }
        })
        .catch(error => {
            console.error('Error:', error);
            alert('评论失败，请重试');
        });
}

// 点赞评论
function likeComment(commentId) {
    fetch(`/comments/${commentId}/like`, {
        method: 'POST'
    })
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                location.reload();
            } else {
                alert(data.message || '点赞失败');
            }
        })
        .catch(error => {
            console.error('Error:', error);
            alert('点赞失败，请重试');
        });
}

// 点赞情侣
document.querySelector('.like-btn').addEventListener('click', function() {
    const coupleId = this.dataset.id;

    fetch(`/couples/${coupleId}/like`, {
        method: 'POST'
    })
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                location.reload();
            } else {
                alert(data.message || '点赞失败');
            }
        })
        .catch(error => {
            console.error('Error:', error);
            alert('点赞失败，请重试');
        });
});